const sqlite3 = require('sqlite3').verbose();
const path = require('path');

// 连接数据库
const dbPath = path.join(__dirname, 'database.db');
const db = new sqlite3.Database(dbPath);

console.log('查询config_data表中的起始地址数据...');

db.all('SELECT id, sequence_number, start_addr, type FROM config_data LIMIT 10', (err, rows) => {
  if (err) {
    console.error('查询失败:', err.message);
    return;
  }
  
  console.log('数据库中的数据:');
  console.table(rows);
  
  // 统计起始地址为0或空的记录数
  db.get('SELECT COUNT(*) as count FROM config_data WHERE start_addr = "0" OR start_addr = "" OR start_addr IS NULL', (err, result) => {
    if (err) {
      console.error('统计失败:', err.message);
    } else {
      console.log(`\n起始地址为0或空的记录数: ${result.count}`);
    }
    
    db.close();
  });
});